<template>
  <div class="icons-wrapper">
    <swiper>
      <swiper-slide v-for="(swp, index) of swpArr" :key="index">
        <div class="item-box"
             v-for="item of swp"
             :key="item.id"
        >
          <div class="icon-box">
            <img class="icon-img" :src="item.iconUrl"/>
          </div>
          <p class="item-des">{{item.des}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data: function () {
    return {
      'itemList': [{
        id: '0001',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        des: '景点门票'
      }, {
        id: '0002',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
        des: '深圳必游'
      }, {
        id: '0003',
        iconUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20195/b0026eb6f96fd2daecba0d7982c7e4c8.png',
        des: '9月特惠'
      }, {
        id: '0004',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/50/26ffa31b56646402.png',
        des: '海洋馆'
      }, {
        id: '0005',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/4d/a1eda1a2b8414302.png',
        des: '夜场狂欢'
      }, {
        id: '0006',
        iconUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20194/cba147cf6cfcea7109d0bff6aac6f626.png',
        des: '深圳动物园'
      }, {
        id: '0007',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/a6/6d97515091789602.png',
        des: '世界之窗'
      }, {
        id: '0008',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/b6/37560ece9c62b502.png',
        des: '东部华侨城'
      }, {
        id: '0009',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
        des: '一日游'
      }, {
        id: '0010',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/b1/528a9e80403b8c02.png',
        des: '玩转长隆'
      }]
    }
  },
  computed: {
    swpArr: function () {
      var swpArr = []
      this.itemList.forEach(function (item, index) {
        var page = Math.floor(index / 8)
        if (!swpArr[page]) {
          swpArr[page] = []
        }
        swpArr[page].push(item)
      })
      return swpArr
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/mixins.styl'

.icons-wrapper >>> .swiper-container {
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
}

.icons-wrapper .item-box {
  position: relative;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
}

.icons-wrapper .item-box .icon-box {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: .44rem;
}

.icons-wrapper .icon-img {
  display: block;
  height: 100%;
  margin: 0 auto;
}

.icons-wrapper .item-des {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: .44rem;
  line-height: .44rem;
  text-align: center;
  color: #212121;
  ellipsis();
}
</style>
